<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算属性</title>
</head>
<body>
<div id="computed">
    <label>
        姓：<input type="text" v-model="firstName"/>
        名：<input type="text" v-model="lastName"/>
    </label>
    <label>
        <p>全名：{{fullName}}</p>
    </label>
</div>
</body>
<script src="script/vue.js"></script>
<script>
    let vue = new Vue({
        el: '#computed',
        data: {
            firstName: '张',
            lastName: '三'
        },
        // 复杂写法
        // computed: {
        //     fullName: {
        //         get() {
        //             return this.firstName + this.lastName;
        //         },
        //         set(value) {
        //           console.log('数据修改了，修改后的数据未', value);
        //           this.firstName = value.substring(0, 1);
        //           this.lastName = value.substring(1);
        //         }
        //     }
        // }

        //简化写法，只有考虑读写，不考虑修改时才能用此简写法
        computed: {
            fullName: function () {
                return this.firstName + this.lastName;
            }
        }
    });
</script>
</html>